#!/bin/bash

mysqlsoftpath="/VI"

# Check if user is root
if [ $(id -u) != "0" ]; then
    echo "Error: You must be root to run this script, please use root to install"
    exit 1
fi

echo "=============================remove database...============================="

num=`crontab -l | grep "/VI/mysql/bin/dog"| grep -v "grep" | wc -l`
if [ $num -ge 1 ]; then
sed -i '/\/VI\/mysql/d' /var/spool/cron/root
fi
echo "清除crontab"

echo "stop database..."
service mysql stop
service mysql status

echo "delete chkconfig..."
chkconfig --del mysql

rm -rf /etc/my.cnf
rm -rf /etc/profile.d/mysql.sh
rm -rf ${mysqlsoftpath}/*
rm -rf /etc/init.d/mysql

sleep 10
userdel -r mysql
rm -rf /home/mysql

echo "Remove MySQL SUCCESS!"
